import java.util.concurrent.TimeUnit;

/**
 * @author lzm
 * @date 2025/2/27 19:54
 * @description
 */
public class ThreadStatus {
    public static void main(String[] args) throws InterruptedException {
        // 创建线程要执行的任务
        Runnable task = () -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(Thread.currentThread().getName() + "：打印了hello world");
        };

        // 创建线程
        Thread thread = new Thread(task, "线程1号");
        // 启动线程
        thread.start();
        System.out.println("线程" + thread.getName() + "状态为：" + thread.getState().name());
        // 等两秒钟，等待线程执行完任务
        TimeUnit.SECONDS.sleep(2);
        System.out.println("线程" + thread.getName() + "状态为：" + thread.getState().name());

        // 等待该线程执行完
        thread.join();
    }
}